package com.yang.springcloud.alibaba.service.impl;

import com.yang.springcloud.alibaba.dao.AccountDao;
import com.yang.springcloud.alibaba.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @Author yang
 * @Date 2022/8/29
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountDao accountDao;
    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("------account-service 扣减账户余额开始-------");
        //模拟超时异常，全局事务回滚
        /*try {
            TimeUnit.SECONDS.sleep(20);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
        accountDao.decrease(userId, money);
        log.info("------account-service 扣减账户余额结束-------");
    }
}
